package com.trex.lwlsh.dataDeal;

import com.trex.lwlsh.model.StepModel;
import com.trex.lwlsh.util.HttpclientUtil;
import com.trex.lwlsh.util.LogUtil;
import org.testng.annotations.Test;
import sun.applet.Main;

import java.io.IOException;
import java.util.HashMap;

/**
 * Create by Trex on 2018/1/15
 */
public class GetResponse {

    public static void main(String[] args) throws Exception {
        GetResponse g=new GetResponse();
        StepModel a=new StepModel();
        g.GetResponse(a);
    }
    /**
     * 分解步骤请求方式，获取步骤返回值
     * @param step
     * @return
     * @throws Exception
     */
    public  String GetResponse(StepModel step) throws Exception {
        String response=new String();
        //传递的参数可能带有${},需要把这个值替换url再请求
        String urlPath=ParametersFactory.Extraction(step.getUrl());
       // String urlPath=ParametersFactory.Extraction("http://www.baidu.com/bug_id=${bug} ");
        String paramList=ParametersFactory.Extraction(step.getParameter());
        String Method = step.getMethod();
        HttpclientUtil httpclientUtil=new HttpclientUtil();
        System.out.println(urlPath+"###############");
        try{
            switch (Method) {
                case "GET":
                    response=httpclientUtil.sendGet(urlPath,paramList);
                    break;
                case "POST":
                    response=httpclientUtil.sendPost(urlPath,paramList);
                    break;
                case "Sql-select":
                   // new SqlConnection().Select(urlPath);
                    break;
                case "Sql-update":
                  // new  SqlConnection().insert(urlPath);
                    break;
                case "sleep":
                   // response = Action.sleep(Url);
                    break;
            }}catch (Exception e){

            LogUtil.saveELog(e);
        }

        return response;
    }




}
